/*LICENSE_BEGIN
 * ******************************************************************
 * Copyright 2006 by the Dainamite Robocup-Team at the
 * DAI-Labor, TU-Berlin (www.dai-labor.de)
 * 
 * Members of Dainamite are:
 * Holger Endert
 * Robert Wetzker
 * Thomas Karbe
 * Axel Heßler
 * Philippe Bütter
 * Felix Brossmann
 * 
 * Licensed under the GNU GPL (General Public License) Free Software 
 * License, Version 2. You may use this file only in compliance with 
 * the License. You may obtain a copy of the License at:
 * 
 * http://www.fsf.org/licensing/licenses/gpl.txt
 * ******************************************************************
LICENSE_END*/
package robocup.component.speechacts.coachlanguage;

import java.util.LinkedList;

public class CoachSayAction {

	private TypeConstants.MESSAGETYPE messageType = TypeConstants.MESSAGETYPE.INIT;

	private String freeformMessage = "";

	private RuleMessage ruleMessage = null;

	private AdviceMessage adviceMessage = null;

	private InfoMessage infoMessage = null;

	private MetaMessage metaMessage = null;

	private DeleteMessage deleteMessage = null;

	private LinkedList<DefineMessage> defineList = new LinkedList<DefineMessage>();

	public CoachSayAction() {

	}

	public TypeConstants.MESSAGETYPE getMessageType() {
		return this.messageType;
	}

	public void setMessageType(TypeConstants.MESSAGETYPE messageType) {
		this.messageType = messageType;
	}

	public RuleMessage getRuleMessage() {
		return this.ruleMessage;
	}

	public void setRuleMessage(RuleMessage ruleMessage) {
		this.ruleMessage = ruleMessage;
		this.messageType = TypeConstants.MESSAGETYPE.RULE;
	}

	public String getFreeformMessage() {
		return this.freeformMessage;
	}

	public void setFreeformMessage(String freeformMessage) {
		if (freeformMessage.startsWith("\""))
			freeformMessage = freeformMessage.substring(1, freeformMessage
					.length() - 1);
		this.freeformMessage = freeformMessage;
		this.messageType = TypeConstants.MESSAGETYPE.FREEFORM;
	}

	public void addDefine(DefineMessage define) {
		this.defineList.add(define);
		this.messageType = TypeConstants.MESSAGETYPE.DEFINE;
	}

	public LinkedList<DefineMessage> getDefineList() {
		return defineList;
	}

	public void setDefineList(LinkedList<DefineMessage> defineList) {
		this.defineList = defineList;
		this.messageType = TypeConstants.MESSAGETYPE.DEFINE;
	}

	public AdviceMessage getAdviceMessage() {
		return adviceMessage;
	}

	public void setAdviceMessage(AdviceMessage adviceMessage) {
		this.adviceMessage = adviceMessage;
		this.messageType = TypeConstants.MESSAGETYPE.ADVICE;
	}

	public InfoMessage getInfoMessage() {
		return infoMessage;
	}

	public void setInfoMessage(InfoMessage infoMessage) {
		this.infoMessage = infoMessage;
		this.messageType = TypeConstants.MESSAGETYPE.INFO;
	}

	public MetaMessage getMetaMessage() {
		return metaMessage;
	}

	public void setMetaMessage(MetaMessage metaMessage) {
		this.metaMessage = metaMessage;
		this.messageType = TypeConstants.MESSAGETYPE.META;
	}

	public DeleteMessage getDeleteMessage() {
		return deleteMessage;
	}

	public void setDeleteMessage(DeleteMessage deleteMessage) {
		this.deleteMessage = deleteMessage;
		this.messageType = TypeConstants.MESSAGETYPE.DELETE;
	}

	public String toString() {
		StringBuffer buf = new StringBuffer();

		buf.append("(say ");

		switch (this.messageType) {

		case INIT:
			buf.append("empty");
			break;

		case FREEFORM:
			buf.append("(freeform \"" + this.freeformMessage + "\")");
			break;

		case RULE:
			buf.append(this.ruleMessage.toString());
			break;

		case DELETE:
			buf.append(this.deleteMessage.toString());
			break;

		case DEFINE:
			buf.append("(define");
			for (DefineMessage dm : this.defineList) {
				buf.append(" " + dm.toString());
			}
			buf.append(")");
			break;

		case META:
			buf.append(this.metaMessage.toString());
			break;

		case ADVICE:
			buf.append(this.adviceMessage.toString());
			break;

		case INFO:
			buf.append(this.infoMessage.toString());
			break;
		}

		buf.append(")");
		return buf.toString();
	}

}
